<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">
  <link rel="stylesheet" href="/lib/pace/pace-theme-minimal.min.css">
  <script src="/lib/pace/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"lanqilu.github.io","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":true},"copycode":{"enable":true,"show_result":true,"style":null},"back2top":{"enable":true,"sidebar":true,"scrollpercent":true},"bookmark":{"enable":false,"color":"#395ca3","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":false,"pangu":true,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="Git的常见使用">
<meta property="og:type" content="article">
<meta property="og:title" content="Git的常见使用">
<meta property="og:url" content="https://lanqilu.github.io/2019/03/12/DevelopTools/Git%E7%AE%80%E5%8D%95%E4%BD%BF%E7%94%A8/index.html">
<meta property="og:site_name" content="Halo">
<meta property="og:description" content="Git的常见使用">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://img.whl123456.top/image/GitHubSSH.png">
<meta property="og:image" content="http://img.whl123456.top/image/image-20200613103720281.png">
<meta property="article:published_time" content="2019-03-12T12:28:50.000Z">
<meta property="article:modified_time" content="2020-08-08T23:58:36.715Z">
<meta property="article:author" content="Lanqilu">
<meta property="article:tag" content="Git">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://img.whl123456.top/image/GitHubSSH.png">

<link rel="canonical" href="https://lanqilu.github.io/2019/03/12/DevelopTools/Git%E7%AE%80%E5%8D%95%E4%BD%BF%E7%94%A8/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>Git的常见使用 | Halo</title>
  
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-161500949-1"></script>
    <script data-pjax>
      if (CONFIG.hostname === location.hostname) {
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());
        gtag('config', 'UA-161500949-1');
      }
    </script>


  <script data-pjax>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?256151d1651e9d73ec980b2fc69de8f6";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Halo</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签<span class="badge">39</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类<span class="badge">18</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档<span class="badge">85</span></a>

  </li>
        <li class="menu-item menu-item-python">

    <a href="/categories/Python/" rel="section"><i class="fa fa-fw fa-code"></i>Python</a>

  </li>
        <li class="menu-item menu-item-java">

    <a href="/categories/Java/" rel="section"><i class="fa fa-fw fa-code"></i>Java</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="reading-progress-bar"></div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://lanqilu.github.io/2019/03/12/DevelopTools/Git%E7%AE%80%E5%8D%95%E4%BD%BF%E7%94%A8/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="http://img.whl123456.top/image/avatar.jpg">
      <meta itemprop="name" content="Lanqilu">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Halo">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Git的常见使用
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2019-03-12 20:28:50" itemprop="dateCreated datePublished" datetime="2019-03-12T20:28:50+08:00">2019-03-12</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-08-09 07:58:36" itemprop="dateModified" datetime="2020-08-09T07:58:36+08:00">2020-08-09</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Git/" itemprop="url" rel="index"><span itemprop="name">Git</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <div class="note info no-icon">
            <p>Git的常见使用</p>
          </div>

<a id="more"></a>

<hr>
<h2 id="配置GitHub"><a href="#配置GitHub" class="headerlink" title="配置GitHub"></a>配置GitHub</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git config --global user.name "your_name"</span><br><span class="line">git config --global user.email "your_email@example.com"</span><br></pre></td></tr></table></figure>

<p>在windows系统中的<code>C:\Users\用户名\.ssh</code>中会产生<code>.ssh</code>文件夹中会生成一对密钥包括<code>id_rsa</code>私钥和<code>id_rsa.pub</code>公钥文件</p>
<p>如果不存在，在Git Bash使用以下命令生成</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh-keygen -t rsa -C "your_email@example.com"</span><br></pre></td></tr></table></figure>

<p>将会弹出以下信息</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">Generating public/private rsa key pair.</span><br><span class="line">Enter file <span class="keyword">in</span> <span class="built_in">which</span> to save the key (/c/Users/用户名/.ssh/id_rsa):  回车</span><br><span class="line">Created directory <span class="string">'/c/Users/用户名/.ssh'</span>.</span><br><span class="line">Enter passphrase (empty <span class="keyword">for</span> no passphrase):    回车或输密码</span><br><span class="line">Enter same passphrase again:                   回车或再一次输密码</span><br><span class="line">Your identification has been saved <span class="keyword">in</span> /c/Users/用户名/.ssh/id_rsa</span><br><span class="line">Your public key has been saved <span class="keyword">in</span> /c/Users/用户名/.ssh/id_rsa.pub</span><br><span class="line">The key fingerprint is:</span><br><span class="line">SHA256:JAldGP+8XXXXXXXXXXXRhzaEpUd5hJfTn0zrJxhXbFYM your_email@example.com</span><br><span class="line">The key<span class="string">'s randomart image is:</span></span><br><span class="line"><span class="string">+---[RSA 3072]----+</span></span><br><span class="line"><span class="string">|    ..o=*..   .o |</span></span><br><span class="line"><span class="string">|     +o= +   E  o|</span></span><br><span class="line"><span class="string">|    . + = . . . .|</span></span><br><span class="line"><span class="string">|     . B + o . +.|</span></span><br><span class="line"><span class="string">|    + O S o o + .|</span></span><br><span class="line"><span class="string">|   = @ o . = =   |</span></span><br><span class="line"><span class="string">|  . B o   o B    |</span></span><br><span class="line"><span class="string">|     o     . .   |</span></span><br><span class="line"><span class="string">|                 |</span></span><br><span class="line"><span class="string">+----[SHA256]-----+</span></span><br></pre></td></tr></table></figure>

<p>将<code>id_rsa.pub</code>公钥文件放到Setting中的SSH and GPG keys中</p>
<p><img src="http://img.whl123456.top/image/GitHubSSH.png" alt="GitHub"></p>
<p>在Git Bash中输入以下命令，验证是否成功</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh -T git@github.com</span><br></pre></td></tr></table></figure>

<p>如果成功则会显示以下消息</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Hi your_name! You've successfully authenticated, but GitHub does not provide shell access.</span><br></pre></td></tr></table></figure>

<h3 id="创建版本库"><a href="#创建版本库" class="headerlink" title="创建版本库"></a>创建版本库</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">mkdir &lt;文件夹名&gt;</span><br><span class="line">cd &lt;文件名&gt;</span><br><span class="line">pwd</span><br></pre></td></tr></table></figure>

<p><code>git init</code> 把这个目录变成Git可以管理的仓库</p>
<p>结果生成.git 隐藏文件夹 （不要手动修改文件夹的内容）</p>
<blockquote>
<p>注意事项<br>不要使用Windows自带的记事本编辑任何文件<br>默认编码设置成UTF-8 without BOM</p>
</blockquote>
<p><img src="http://img.whl123456.top/image/image-20200613103720281.png" alt="image-20200613103720281"></p>
<h3 id="文件放到Git仓库目录下"><a href="#文件放到Git仓库目录下" class="headerlink" title="文件放到Git仓库目录下"></a>文件放到Git仓库目录下</h3><p><code>git status</code></p>
<p><code>git add &lt;file&gt;</code></p>
<p><code>git add .</code>提交新文件和被修改文件，不包括被删除文件</p>
<p><code>git add -u</code>提交被修改和被删除文件，不包括新文件</p>
<p><code>git add -A</code>提交所有变化</p>
<p><code>git add -i</code></p>
<blockquote>
<p>Unix哲学 “没有消息就是好消息”</p>
</blockquote>
<h3 id="把文件提交到仓库"><a href="#把文件提交到仓库" class="headerlink" title="把文件提交到仓库"></a>把文件提交到仓库</h3><p><code>git commit -m &lt;message&gt;</code>-m 后面输入本次提交的说明</p>
<p><code>git commit --amend</code>修改最近一次提交的注释信息</p>
<h3 id="vim编辑器的使用"><a href="#vim编辑器的使用" class="headerlink" title="vim编辑器的使用"></a>vim编辑器的使用</h3><p><code>vi &lt;filename&gt;</code></p>
<p>输入字母<code>i</code>或Insert键进入最常用的插入编辑模式<br>按下字母键 <code>c</code>（此时进入编辑状态），可以开始修改注释信息了<br>按下Esc (退出编辑状态)<br>接着连按两次大写字母<code>Z</code>，保存并退出<br>只想保存文件，则键入:<code>w</code><br>放弃所有文件修改：按下ESC键进入命令模式，键入:<code>q!</code>回车后放弃修改并退出vi<br><code>.</code>放弃所有文件修改，但不退出 vi:<br>按下ESC键进入命令模式，键入:<code>e!</code>，回车后回到命令模式</p>
<h3 id="修改文件后"><a href="#修改文件后" class="headerlink" title="修改文件后"></a>修改文件后</h3><p><code>git stautus</code> 掌握仓库当前的状态</p>
<blockquote>
<p>On branch master<br>nothing to commit, working tree clean</p>
</blockquote>
<p><code>git diff &lt;file&gt;</code>#看具体修改了什么内容<br>再<code>git add &lt;file&gt;</code></p>
<p><code>git log</code>#历史记录 显示从最近到最远的提交日志  </p>
<p><code>git log --pretty=oneline</code>oneline 压缩模式</p>
<h3 id="退回之前的版本"><a href="#退回之前的版本" class="headerlink" title="退回之前的版本"></a>退回之前的版本</h3><p>就是HEAD^，上上一个版本就是HEAD^^，当然往上100个版本写100个^比较容易数不过来，所以写成HEAD~100<br><code>git reset --hard HEAD^</code></p>
<p><code>git reflog</code>#记录你的每一次命令<br><code>git reset --hard &lt;commit id&gt;</code>（id不必写全）</p>
<h3 id="修改"><a href="#修改" class="headerlink" title="修改"></a>修改</h3><p><code>git checkout -- &lt;file&gt;</code><br>丢弃 工作区 的修改  在工作区的修改全部撤销，<br>让这个文件回到最近一次git commit或git add时的状态</p>
<p><code>git reset HEAD &lt;file&gt;</code><br>既可以回退版本，也可以把暂存区的修改回退到工作区</p>
<h3 id="删除文件"><a href="#删除文件" class="headerlink" title="删除文件"></a>删除文件</h3><p><code>rm &lt;file&gt;</code>     #删除工作区文件<br><code>git rm &lt;file&gt;</code> #从版本库中删除该文件</p>
<p>先手动删除文件，然后使用git add<file>效果是一样的<br>git checkout  – <file>   #把误删的文件恢复到最新版本（用版本库里的版本替换工作区的版本）</p>
<h3 id="分支"><a href="#分支" class="headerlink" title="分支"></a>分支</h3><p><code>git checkout -b &lt;branchname&gt;</code> #创建分支,然后切换到分支<br><code>git branch &lt;branchname&gt;</code>      #创建分支<br><code>git checkout &lt;branchname&gt;</code>    #切换到分支<br><code>git branch</code>                   #查看当前分支<br><code>git checkout master</code>          #换回master分支<br><code>git merge &lt;branchname&gt;</code>       #合并指定分支到当前分支<br><code>git branch -d &lt;branchname&gt;</code>   #删除分支<br><code>git branch -m &lt;branchname&gt;</code>   #重命名分支</p>
<h2 id="GitHub"><a href="#GitHub" class="headerlink" title="GitHub"></a>GitHub</h2><h3 id="推送"><a href="#推送" class="headerlink" title="推送"></a>推送</h3><p>关联一个远程库并推送</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git remote add origin git@Lanqilu:path/&lt;repo-name&gt;.git</span><br><span class="line">git push -u origin master</span><br></pre></td></tr></table></figure>

<h3 id="克隆"><a href="#克隆" class="headerlink" title="克隆"></a>克隆</h3><p><code>git clone &lt;url&gt;</code></p>
<h3 id="拉取"><a href="#拉取" class="headerlink" title="拉取"></a>拉取</h3><p><code>git pull</code></p>
<ol>
<li><p>服务器代码合并本地代码</p>
 <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git stash     //暂存当前正在进行的工作。</span><br><span class="line">git pull origin master //拉取服务器的代码</span><br><span class="line">git stash pop //合并暂存的代码</span><br></pre></td></tr></table></figure>
</li>
<li><p>服务器代码覆盖本地代码</p>
 <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git reset --hard  //回滚到上一个版本</span><br><span class="line">git pull origin master</span><br></pre></td></tr></table></figure>

</li>
</ol>
<h3 id="版本控制"><a href="#版本控制" class="headerlink" title="版本控制"></a>版本控制</h3><p><code>git log</code></p>
<p><code>git log --pretty=oneline</code></p>
<p><code>git log --oneline</code></p>
<p><code>git reflog</code></p>
<p><code>git reset --hard [部分索引值]</code></p>
<h3 id="隐藏文件"><a href="#隐藏文件" class="headerlink" title="隐藏文件"></a>隐藏文件</h3><p>exclude</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> git ls-files --others --exclude-from=.git/info/exclude</span></span><br><span class="line"><span class="meta">#</span><span class="bash"> Lines that start with <span class="string">'#'</span> are comments.</span></span><br><span class="line"><span class="meta">#</span><span class="bash"> For a project mostly <span class="keyword">in</span> C, the following would be a good <span class="built_in">set</span> of</span></span><br><span class="line"><span class="meta">#</span><span class="bash"> exclude patterns (uncomment them <span class="keyword">if</span> you want to use them):</span></span><br><span class="line"><span class="meta">#</span><span class="bash"> *.[oa]</span></span><br><span class="line"><span class="meta">#</span><span class="bash"> *~</span></span><br><span class="line">.*</span><br></pre></td></tr></table></figure>

<h3 id="忽略文件"><a href="#忽略文件" class="headerlink" title="忽略文件"></a>忽略文件</h3><p><code>touch .gitignore</code><br><code>.git/info/exclude``
``vi .git/info/exclude</code></p>
<ol>
<li>忽略文件中的空行或以井号( #告开始的行将会被忽略。</li>
<li>可以使用Linux通配符。例如:星号(* )代表任意多个字符,问号( ? ) 代表-一个字符 ,方括号( [abc] )代表可选字符范围,<br>大括号( {string1,string…. )代表可选的字符串等。</li>
<li>如果名称的最前面有一一个感叹号(!) , 表示例外规则,将不被忽略。</li>
<li>如果名称的最前面是一个路径分隔符 (/ ) , 表示要忽略的文件在此目录下,而子目录中的文件不忽略。</li>
<li>如果名称的最后面是一个路径分隔符(/) , 表示要忽略的是此目录下该名称的子目录,而非文件(默认文件或目录都忽略)。</li>
</ol>
<h3 id="删除远程文件"><a href="#删除远程文件" class="headerlink" title="删除远程文件"></a>删除远程文件</h3><p>方法一<br>这里以删除 test文件夹为案例</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git rm -r --cached test //--cached不会把本地的test删除</span><br><span class="line">git commit -m 'delete test '</span><br><span class="line">git push -u origin master</span><br></pre></td></tr></table></figure>

<p>方法二<br>如果误提交的文件夹比较多，方法一也较繁琐<br>直接修改.gitignore文件,将不需要的文件过滤掉，然后执行命令:</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">git rm -r --cached .</span><br><span class="line">git add .</span><br><span class="line">git commit</span><br><span class="line">git push -u origin master</span><br></pre></td></tr></table></figure>

<blockquote>
<p><a href="https://blog.csdn.net/cui130/article/details/84033966" target="_blank" rel="noopener">参考博客</a></p>
</blockquote>
<h3 id="下载文件"><a href="#下载文件" class="headerlink" title="下载文件"></a>下载文件</h3><p>单个文件<a href="https://minhaskamal.github.io/DownGit/#/home" target="_blank" rel="noopener">DownGit</a>，国内访问较慢</p>
<p>将仓库克隆到码云上在下载</p>
<p>使用迅雷</p>
<h2 id="错误"><a href="#错误" class="headerlink" title="错误"></a>错误</h2><ol>
<li>原因是因为上传时间太长了，导致ssh连接超时断开</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">fatal: sha1 file '&lt;stdout&gt;' write error: Broken pipe KiB/s</span><br><span class="line">fatal: the remote end hung up unexpectedly</span><br><span class="line">fatal: the remote end hung up unexpectedly</span><br></pre></td></tr></table></figure>

<blockquote>
<p><a href="https://blog.csdn.net/qq_31803503/article/details/88323527" target="_blank" rel="noopener">解决方案</a></p>
</blockquote>
<h3 id="push问题"><a href="#push问题" class="headerlink" title="push问题"></a>push问题</h3><h4 id="rejected-master-gt-master-non-fast-forward"><a href="#rejected-master-gt-master-non-fast-forward" class="headerlink" title="! [rejected] master -&gt; master (non-fast-forward)"></a>! [rejected] master -&gt; master (non-fast-forward)</h4><h5 id="错误-1"><a href="#错误-1" class="headerlink" title="错误"></a>错误</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash"> git push</span></span><br><span class="line">To github.com:Lanqilu/BiliBilil-Leaderboard.git</span><br><span class="line"> ! [rejected]        master -&gt; master (non-fast-forward)</span><br><span class="line">error: failed to push some refs to 'git@github.com:Lanqilu/BiliBilil-Leaderboard.git'</span><br><span class="line">hint: Updates were rejected because the tip of your current branch is behind</span><br><span class="line">hint: its remote counterpart. Integrate the remote changes (e.g.</span><br><span class="line">hint: 'git pull ...') before pushing again.</span><br><span class="line">hint: See the 'Note about fast-forwards' in 'git push --help' for details.</span><br></pre></td></tr></table></figure>

<h5 id="问题"><a href="#问题" class="headerlink" title="问题"></a>问题</h5><p>git仓库中已经有一部分代码，所以它不允许你直接把你的代码覆盖上去</p>
<h5 id="解决方法"><a href="#解决方法" class="headerlink" title="解决方法"></a>解决方法</h5><p>利用强覆盖方式用你本地的代码替代git仓库内的内容</p>
<blockquote>
<p>不推荐使用，需要解决冲突再提交</p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git push -f</span><br></pre></td></tr></table></figure>

<p><a href="https://blog.csdn.net/lujinjian605894472/article/details/8443403" target="_blank" rel="noopener">参考地址</a></p>
<!--hexo clean && hexo g && hexo d-->

<h3 id="pull问题"><a href="#pull问题" class="headerlink" title="pull问题"></a>pull问题</h3><h4 id="问题描述：本地内容有修改但要与pull"><a href="#问题描述：本地内容有修改但要与pull" class="headerlink" title="问题描述：本地内容有修改但要与pull"></a>问题描述：本地内容有修改但要与pull</h4><h4 id="解决办法"><a href="#解决办法" class="headerlink" title="解决办法"></a>解决办法</h4><p>先git status暂存</p>
<p>再pull之后git status pop 选择修改</p>

    </div>

    
    
    
      


      <footer class="post-footer">
          
          <div class="post-tags">
              <a href="/tags/Git/" rel="tag"><i class="fa fa-tag"></i> Git</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item"></div>
      <div class="post-nav-item">
    <a href="/2019/05/08/DevelopTools/Markdown%E8%AF%AD%E6%B3%95/" rel="next" title="Markdown基本语法">
      Markdown基本语法 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#配置GitHub"><span class="nav-number">1.</span> <span class="nav-text">配置GitHub</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#创建版本库"><span class="nav-number">1.1.</span> <span class="nav-text">创建版本库</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#文件放到Git仓库目录下"><span class="nav-number">1.2.</span> <span class="nav-text">文件放到Git仓库目录下</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#把文件提交到仓库"><span class="nav-number">1.3.</span> <span class="nav-text">把文件提交到仓库</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#vim编辑器的使用"><span class="nav-number">1.4.</span> <span class="nav-text">vim编辑器的使用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#修改文件后"><span class="nav-number">1.5.</span> <span class="nav-text">修改文件后</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#退回之前的版本"><span class="nav-number">1.6.</span> <span class="nav-text">退回之前的版本</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#修改"><span class="nav-number">1.7.</span> <span class="nav-text">修改</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#删除文件"><span class="nav-number">1.8.</span> <span class="nav-text">删除文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#分支"><span class="nav-number">1.9.</span> <span class="nav-text">分支</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#GitHub"><span class="nav-number">2.</span> <span class="nav-text">GitHub</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#推送"><span class="nav-number">2.1.</span> <span class="nav-text">推送</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#克隆"><span class="nav-number">2.2.</span> <span class="nav-text">克隆</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#拉取"><span class="nav-number">2.3.</span> <span class="nav-text">拉取</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#版本控制"><span class="nav-number">2.4.</span> <span class="nav-text">版本控制</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#隐藏文件"><span class="nav-number">2.5.</span> <span class="nav-text">隐藏文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#忽略文件"><span class="nav-number">2.6.</span> <span class="nav-text">忽略文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#删除远程文件"><span class="nav-number">2.7.</span> <span class="nav-text">删除远程文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#下载文件"><span class="nav-number">2.8.</span> <span class="nav-text">下载文件</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#错误"><span class="nav-number">3.</span> <span class="nav-text">错误</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#push问题"><span class="nav-number">3.1.</span> <span class="nav-text">push问题</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#rejected-master-gt-master-non-fast-forward"><span class="nav-number">3.1.1.</span> <span class="nav-text">! [rejected] master -&gt; master (non-fast-forward)</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#错误-1"><span class="nav-number">3.1.1.1.</span> <span class="nav-text">错误</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#问题"><span class="nav-number">3.1.1.2.</span> <span class="nav-text">问题</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#解决方法"><span class="nav-number">3.1.1.3.</span> <span class="nav-text">解决方法</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#pull问题"><span class="nav-number">3.2.</span> <span class="nav-text">pull问题</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#问题描述：本地内容有修改但要与pull"><span class="nav-number">3.2.1.</span> <span class="nav-text">问题描述：本地内容有修改但要与pull</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#解决办法"><span class="nav-number">3.2.2.</span> <span class="nav-text">解决办法</span></a></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Lanqilu"
      src="http://img.whl123456.top/image/avatar.jpg">
  <p class="site-author-name" itemprop="name">Lanqilu</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">85</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">18</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">39</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/lanqilu" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;lanqilu" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i></a>
      </span>
      <span class="links-of-author-item">
        <a href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=zqKvoL_noruOqKG2o6_nouCtoaM" title="E-Mail → http:&#x2F;&#x2F;mail.qq.com&#x2F;cgi-bin&#x2F;qm_share?t&#x3D;qm_mailme&amp;email&#x3D;zqKvoL_noruOqKG2o6_nouCtoaM" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i></a>
      </span>
  </div>



      </div>
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 2019 – 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Lanqilu</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/pjax/pjax.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/pangu@4/dist/browser/pangu.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>

  <script>
var pjax = new Pjax({
  selectors: [
    'head title',
    '#page-configurations',
    '.content-wrap',
    '.post-toc-wrap',
    '.languages',
    '#pjax'
  ],
  switches: {
    '.post-toc-wrap': Pjax.switches.innerHTML
  },
  analytics: false,
  cacheBust: false,
  scrollTo : !CONFIG.bookmark.enable
});

window.addEventListener('pjax:success', () => {
  document.querySelectorAll('script[data-pjax], script#page-configurations, #pjax script').forEach(element => {
    var code = element.text || element.textContent || element.innerHTML || '';
    var parent = element.parentNode;
    parent.removeChild(element);
    var script = document.createElement('script');
    if (element.id) {
      script.id = element.id;
    }
    if (element.className) {
      script.className = element.className;
    }
    if (element.type) {
      script.type = element.type;
    }
    if (element.src) {
      script.src = element.src;
      // Force synchronous loading of peripheral JS.
      script.async = false;
    }
    if (element.dataset.pjax !== undefined) {
      script.dataset.pjax = '';
    }
    if (code !== '') {
      script.appendChild(document.createTextNode(code));
    }
    parent.appendChild(script);
  });
  NexT.boot.refresh();
  // Define Motion Sequence & Bootstrap Motion.
  if (CONFIG.motion.enable) {
    NexT.motion.integrator
      .init()
      .add(NexT.motion.middleWares.subMenu)
      .add(NexT.motion.middleWares.postList)
      .bootstrap();
  }
  NexT.utils.updateSidebarPosition();
});
</script>




  




  
<script src="/js/local-search.js"></script>













    <div id="pjax">
  

  

  

    </div>
</body>
</html>
